package com.mall.bargain.controller;

import com.github.pagehelper.PageInfo;
import com.mall.bargain.service.BargainListService;
import com.mall.bargain.service.BargainingRecordService;
import com.mall.bargain.vo.BargainUser;
import com.mall.common.response.CommonResponse;
import com.mall.constant.enums.CommonStatus;
import com.mall.constant.strings.SuccessMsg;
import com.mall.entity.bargain.BgBargain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LiJinYang
 * @version 1.0
 * @email 283006176@qq.com
 * @date 2021/07/19 16:08
 */
@RestController
@RequestMapping("/bargainlist")
@CrossOrigin
public class BargainListController {

    @Autowired
    private BargainListService bargainListService;
    @Autowired
    private BargainingRecordService bargainingRecordService;

    /**
     * 查询全部
     * @return
     */
    @GetMapping("findAll")
    public List<BgBargain> findAll(){
        return bargainListService.findAll();
    }

    /**
     * 分页查询
     * @param page
     * @param size
     * @param bgBargain
     * @return
     */
    @PostMapping("findPage")
    public CommonResponse findPage(@RequestParam(value = "page",defaultValue = "1")int page
            , @RequestParam(value = "size",defaultValue ="2" )int size
            , @RequestBody BgBargain bgBargain){
        try{
            return new CommonResponse(0,"操作成功",bargainListService.findPage(page,size, bgBargain));
        }catch (Exception e){
            e.printStackTrace();
            return new CommonResponse(0,"操作失败",bargainListService.findPage(page,size, bgBargain));
        }

    }

    /**
     * 根据ID逻辑删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public CommonResponse delete(Long id){
            return bargainListService.delete(id);
    }

    /**
     * 查看商品的砍价详情（根据ID查询）
     * @param id
     * @return
     */
    @GetMapping("/seeDetails")
    public CommonResponse seeDetails(Integer id){
        return bargainingRecordService.seeDetails(id);
    }


}
